from pygame import mixer

class SoundPlayer():

    '''
        数字对应的音频文件映射，不用频繁的if else
    '''
    amountMapAudio = {
        18: '/home/pi/Bookshelf/count/audios/a1.mp3',
        19: '/home/pi/Bookshelf/count/audios/a2.mp3',
        20: '/home/pi/Bookshelf/count/audios/a3.mp3',
        21: '/home/pi/Bookshelf/count/audios/a4.mp3',
        22: '/home/pi/Bookshelf/count/audios/a5.mp3',
        23: '/home/pi/Bookshelf/count/audios/a6.mp3',
        24: '/home/pi/Bookshelf/count/audios/a7.mp3',
        25: '/home/pi/Bookshelf/count/audios/a8.mp3',
        26: '/home/pi/Bookshelf/count/audios/a9.mp3',
        27: '/home/pi/Bookshelf/count/audios/a10.mp3',
        28: '/home/pi/Bookshelf/count/audios/a11.mp3',
        29: '/home/pi/Bookshelf/count/audios/a12.mp3',
        30: '/home/pi/Bookshelf/count/audios/a13.mp3',
        31: '/home/pi/Bookshelf/count/audios/a14.mp3',
        32: '/home/pi/Bookshelf/count/audios/a15.mp3',
    }

    '''
        # 混合器 提示 需要初始化
    '''
    @staticmethod
    def init():
        mixer.init()

    '''
        播放数字对应音频, 静态方法，不需要实例化类，可以直接调用
    '''
    @staticmethod
    def play(a):
        if a < 33 and a > 17:
            audio = SoundPlayer.amountMapAudio[a]
            mixer.music.load(audio)
            mixer.music.play()
        if a >= 33:
            mixer.music.load('/home/pi/Bookshelf/count/audios/ada.mp3')
            mixer.music.play()
        if a <= 17:
            mixer.music.load('/home/pi/Bookshelf/count/audios/axa.mp3')
            mixer.music.play()